package com.cqupt.service.impl;

import com.cqupt.common.WebLog;
import com.cqupt.service.LogService;
import lombok.extern.log4j.Log4j2;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Service;

import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.Date;

@Service
@Log4j2
public class LogServiceImpl implements LogService {
    @Override
    public void printConsoleLog(ProceedingJoinPoint pj, WebLog annotation) {

        //获取当前执行用户
        //HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        //Person Person = (Person) request.getSession().getAttribute(Const.CURRENT_USER);

        //获取当前执行操作的用户对象
        //log.info("当前用户："+Person.getName());
        log.info("当前用户执行模块:" + annotation.value());

        //获取方法名
        log.info("当前用户执行方法："+pj.getSignature().getName());

        Method method=((MethodSignature)pj.getSignature()).getMethod();
        log.info("当前方法的放回类型"+method.getReturnType());
        //获取系统时间
        String time = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss").format(new Date());
        log.info("当前用户操作时间："+time);
        for(Object obj : pj.getArgs()){
            log.info("当前用户执行的方法名参数："+obj.toString());
        }
    }
}
